﻿@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}
<div class="poppan">
    <input type="hidden" name="_cId" value="@ViewBag.data["cid"].ToString()" />
    <input type="hidden" name="_guid" value="@ViewBag.Guid" />
    <table>
        <tr>
            <td nowrap>跟进方式</td>
            <td colspan="3">
                @foreach (var dr in ViewBag.dict["AdMode"])
                {
                    <input type="radio" name="_AdMode" value="@dr.Key" @(dr.Key == ViewBag.data["AdMode"].ToString() || dr.Key == "0" ? "checked" : "") title="@dr.Value" />
                }
            </td>
        </tr>
        <tr>
            <td>跟进结果</td>
            <td colspan="3">
                @foreach (var dr in ViewBag.dict["Cusgrade"])
                {
                    <input type="radio" name="_Cusgrade" id="_Cusgrade" lay-filter="_Cusgrade" value="@dr.Key" @(dr.Key == ViewBag.data["Cusgrade"].ToString() || dr.Key == "0" ? "checked" : "") title="@dr.Value" />
                }
            </td>
        </tr>
        <tr id="div1">
            <td id="makeTitle">预约时间</td>
            <td><input type="text" name="_MakeDate" id="_MakeDate" autocomplete="off" class="layui-input"></td>
            <td class="divAuditions">试听选择</td>
            <td class="divAuditions"><input type="checkbox" name="_IsAuditions" id="_IsAuditions" lay-filter="_IsAuditions" title="预约试听" @(ViewBag.data["IsAuditions"].ToString() == "1" ? "checked" : "")></td>
        </tr>
        <tr id="div2">
            <td>下次联系时间</td>
            <td><input type="text" name="_NextMakedate" id="_NextMakedate" autocomplete="off" class="layui-input date"></td>
            <td></td>
            <td></td>
        </tr>
        <tr id="div3">
            <td>课程选择</td>
            <td>
                <select name="_CouTeachId" id="_CouTeachId" lay-verify="required">
                    <option value="0"></option>
                </select>
            </td>
            <td>付费状态</td>
            <td nowrap>
                @foreach (var dr in ViewBag.dict["IsCharge"])
                {
                    <input type="radio" name="_IsCharge" lay-filter="_IsCharge" value="@dr.Key" @(dr.Key == ViewBag.data["IsCharge"].ToString() || dr.Key == "0" ? "checked" : "") title="@dr.Value" />
                }
            </td>
        </tr>

        <tr id="div4">
            <td>付款明细</td>
            <td colspan="3">
                <button class="layui-btn layui-btn-normal" onclick="OpenAccount(@ViewBag.data["cid"].ToString());return false;">填写付费明细</button>
            </td>
        </tr>

        <tr id="div5">
            <td>签订合同</td>
            <td colspan="3">
                <button class="layui-btn layui-btn-normal" onclick="OpenContract(@ViewBag.data["cid"].ToString());return false;">签订合同</button>
            </td>
        </tr>

        <tr>
            <td width="100px;">备注</td>
            <td colspan="3">
                <textarea name="_Remark" class="layui-textarea"></textarea>
            </td>
        </tr>
    </table>
</div>
@section fooler{
<script>
    var Cusgrade = "0";
    layui.use(['element', 'table', 'layer', 'laypage', 'form', 'laydate'], function () {
        var form = layui.form;
        form.on('radio(_Cusgrade)', function (data) {
            Cusgrade = data.value;          
            $("#makeTitle").html('预约时间');
            $(".divAuditions").show();
            if (Cusgrade == "0" ) {
                $("#div1").show();
                $("#div2").hide();
                $("#div3").hide();
                $("#div4").hide();
                $("#div5").hide();
            } else if (Cusgrade == "6") {//交订金
                $("#makeTitle").html('签约时间');
                $(".divAuditions").hide();
                $("#div1").show();
                $("#div2").hide();
                $("#div3").hide();
                $("#div4").show();
                $("#div5").hide();
            } else if (Cusgrade == "7") {//签合同
                $("#div1").hide();
                $("#div2").hide();
                $("#div3").hide();
                $("#div4").hide();
                $("#div5").show();
            } else if (Cusgrade == "8") {//继续联系
                $("#div1").hide();
                $("#div2").show();
                $("#div3").hide();
                $("#div4").hide();
                $("#div5").hide();
            } else if (Cusgrade == "9") {//已到访
                $("#makeTitle").html('到访时间');
                $("#div1").show();
                $("#div2").hide();
                $("#div3").hide();
                $("#div4").hide();
                $("#div5").hide();
            } else {
                $("#div1").hide();
                $("#div2").hide();
                $("#div3").hide();
                $("#div4").hide();
                $("#div5").hide();
            }
        });
        form.on('radio(_IsCharge)', function (data) {
            var val = data.value;
            if (val == "1")            
                $("#div4").show();              
            else
                $("#div4").hide(); 
        });
        form.on('checkbox(_IsAuditions)', function (data) {
            if (data.elem.checked) {
                $("#div3").show();
                var date = $("#_MakeDate").val();
                if (date == "")
                    layui.layer.msg("请选择预约时间");
                else {
                    SetCourse(date);
                }
            }
            else
                $("#div3").hide();
        });
        $("#div2").hide();
        $("#div3").hide();
        $("#div4").hide();
        $("#div5").hide();

        layui.laydate.render({
            elem: '#_MakeDate', //指定元素
            done: function (value, date, endDate) {
                if($('#_IsAuditions').is(':checked'))
                    SetCourse(value);           
            }
        });        
    });
    function SetCourse(date) {//视听课程
        $.ajax({
            type: 'POST',
            url: '../Customer/Followup/Course',
            data: {Ids:'@ViewBag.Ids',KeyCodes:'@ViewBag.KeyCodes',date:date},
            dataType: "json",
            success: function (data) {
                if (data.code == "0000") {
                    var CouTeachId = $("#_CouTeachId");
                    CouTeachId.empty();
                    CouTeachId.append("<option value='0'></option>")
                    for (var i = 0; i < data.data.length; i++) {                                   
                        var dr = data.data[i];                                    
                        CouTeachId.append("<option value='" + dr.id + "'>" + dr.coursename + "</option>");
                    }
                    layui.form.render('select');
                }
                else
                    layui.layer.msg(data.message);
            }
        });
    }
    function SaveSuccessCallBack(res) {
        layui.layer.msg(res.message, {
            time: 500 //2秒关闭（如果不配置，默认是3秒）
        }, function () {
            parent.location.reload();
        });
        return true;
    }
    function OpenAccount(cid) {
        var flowingType = "";//00101001 订金 00102001 合同 00104001 试听
        if (Cusgrade == "0" || Cusgrade == "9") flowingType = "00104001";
        else if (Cusgrade == "6") flowingType = "00101001";
        else if (Cusgrade == "7") flowingType = "00102001";

        var index = layui.layer.open({
            type: 2,            
            content: '../Account/At?id=-1&flowingType='+flowingType+'&guid=@ViewBag.Guid&cid=' + cid,
            title: '填写付费明细',
            area: ['360px', '450px'],
            maxmin: true
        });
        layui.layer.full(index);
    }
    function OpenContract(cid) {
        var index = layui.layer.open({
            type: 2,
            content: '../Contract/ContractList?id=-1&guid=@ViewBag.Guid&cid=' + cid,
            title: '签订合同',
            area: ['360px', '450px'],
            maxmin: true
        });
        layui.layer.full(index);

    }
    //关闭
    function HideModal(id) {
        layui.layer.closeAll();
        layui.table.reload("dgrid");
    }
</script>
}